using UnityEngine;
using System;

public class Jogador : MonoBehaviour
{
	
	public Transform transf;
	private Animator _animator;
	Boolean facingRight = true;
	public float velocidade = 4f;
    private Vector3 LastPosition;
    private static Vector3 staticPosition = new Vector3(4,4,0);
	public enum inputState 
	{ 
		None, 
		A, 
		D, 
		W, 
		S,
		Space
	};

	public virtual void FixedUpdate()
	{	
		if(Input.GetKey(KeyCode.A)) 
		{ 
			if(facingRight) gira ();
			facingRight = false;
			transf.position = new Vector3(transf.position.x-velocidade, transf.position.y, transf.position.z);
            LastPosition = transf.position;
		}
		

		if (Input.GetKey(KeyCode.D)) 
		{ 
			if(!facingRight) 
				gira ();
			facingRight = true;
			transf.position = new Vector3(transf.position.x+velocidade, transf.position.y, transf.position.z);
            LastPosition = transf.position;
		}
		
	
		if (Input.GetKey(KeyCode.W)) 
		{ 
			transf.position = new Vector3(transf.position.x, transf.position.y+velocidade, transf.position.z);
            LastPosition = transf.position;
		}
		

		if(Input.GetKey(KeyCode.S))
		{
			transf.position = new Vector3(transf.position.x, transf.position.y-velocidade, transf.position.z);
            LastPosition = transf.position;
		}



	}

	private void gira() {
		Vector3 theScale = transf.localScale;
		theScale.x *= -1;
		transf.localScale = theScale;
	}

    void OnCollisionEnter2D(Collision2D collision)
    {
        transf.position = LastPosition - staticPosition;
    }
	
}

